﻿$(document).ready(function () {

    $("pre.ms-rteElement-CodeHTML").each(function () {
        addSyntaxStyle($(this), "brush: html");
    });
    $("pre.ms-rteElement-CSharp").each(function () {
        addSyntaxStyle($(this), "brush: csharp");
    });
    $("pre.ms-rteElement-Javascript").each(function () {
        addSyntaxStyle($(this), "brush: js");
    });
    $("pre.ms-rteElement-Powershell").each(function () {
        addSyntaxStyle($(this), "brush: ps");
    });
    $("pre.ms-rteElement-sql").each(function () {
        addSyntaxStyle($(this), "brush: sql");
    });
    $("pre.ms-rteElement-vb").each(function () {
        addSyntaxStyle($(this), "brush: vb");
    });
    SyntaxHighlighter.all();

})

var addSyntaxStyle = function (code, brush) {

    code.removeAttr("class");

    /*** Fixing IE stuff ***/
    var trimedCode = code.html().replace(/<br>/g, "\r\n");
    trimedCode = trimedCode.replace(/<br \/>/g, "\r\n");
    trimedCode = trimedCode.replace(/<BR \/>/g, "\r\n");
    trimedCode = trimedCode.replace(/<BR>/g, "\r\n");
    trimedCode = trimedCode.replace(/<BR\/>/g, "\r\n");
    trimedCode = trimedCode.replace(/<br\/>/g, "\r\n");

    code.html(trimedCode);
    code.replaceWith("<pre class='" + brush + "'>" + trimedCode + "</pre>");

}